const http = require('http'),
    express = require("express"),
    path = require("path"),
    app = express(),
    env = process.env;

app.set("views", path.join(__dirname, "views"));
app.set("view engine", "html");
app.engine(".html", require("ejs").__express);

app.get("/400.html", function(req, res) {
    res.render("400");
});

app.get("/500.html", function(req, res) {
    res.render("500");
});
app.use(express.static('dist'));

app.get("*", function(req, res) {
    res.render(path.join(__dirname, "dist/index.html"));
});

let server = http.createServer(app);

server.listen(env.NODE_PORT || 3000, env.NODE_IP || 'localhost', function() {
    console.log(`Application worker ${process.pid} started...`);
});